/**
 * <p>API基本信息选择字段控件</p>
 * xtype = cceafapi_basefield

 * @module Ext-ux-cceaf-control
 * @class cceaf.control.Api_baseField
 * @extends Ext.form.TriggerField
 * @since 1.0
 */
Ext.define('cceaf.control.msg.SysUser',{
	extend: 'Ext.form.field.Trigger', 
    alias: 'widget.cceafmsg_sysuser',
    requires: [
   	    'cceaf.control.msg.SelectSysUser'
   	],
    
	triggerClass : 'x-form-date-trigger',
	/**
	 * 选择API基本信息
	 *
     * @property nameOfApi_id
     * @type String
     * @default null
     */
	idOfuserid: null,
	
	width: 420,
	
	initComponent : function(){
		cceaf.control.msg.SysUser.superclass.initComponent.call(this);

        this.addEvents(
            'select'
        );
    },

    initEvents: function() {
    	cceaf.control.msg.SysUser.superclass.initEvents.call(this);
        this.keyNav = new Ext.KeyNav(this.el, {
            "down": function(e) {
                this.onTriggerClick();
                
            },
            scope: this,
            forceKeyDown: true
        });
    },
	
    onTriggerClick : function(){
        if(this.disabled){
            return;
        }
        
        this.showSelectWin();
    },
    
    listeners:{
		'focus': function(){
			this.selectText();
		},
		'specialkey': function(obj,e){
			if(e.getKey() == 13){//按Enter
				this.showSelectWin();
			}
			if(e.getKey() == 8){//按Backspace
				this.clearSelectValue();
			}
		}
    },
    
    
    clearSelectValue: function(){
    	if(this.nameOfApi_id != null && this.nameOfApi_id != ""){
    		var api_baseFieldFather = this.up();
    		api_baseFieldFather.down('[name=' + this.nameOfApi_id + ']').setValue('');
		}
    },
    
    showSelectWin: function(){
    	var obj = this;
		var selectApi_baseWin = Ext.getCmp("_selectApi_baseWin");
		if(selectApi_baseWin == null){
			selectApi_baseWin = new Ext.Window({
	    		id:'_selectApi_baseWin',
	        	title: '用户编号',
	        	modal: true,
	        	//closeAction: 'hide',
	        	height: 420,
	        	width: 850,
	        	superobject:obj,
	        	autoScroll: true,
	        	layout: 'fit',
	        	listeners:{
	        		'show': function(){
	        			this.down('[name=q_userid]').focus(true,200);
	        		}
	        	},
	        	items: new cceaf.control.msg.SelectSysUser({
	        		api_baseField: this, 
	        		idOfuserid: this.idOfuserid,
	        		listeners:{
	        			itemdblclick:function(g,r,c,d){
	        				var str='';
	        				var id = r.get('userid');
	        				//alert(id);
	        				//g.up().up().superobject
	        				obj.setValue(id); 
	        				g.up().up().close();
	        			}
	        		}

	        			        		
        	})
			});
		} else{

		}
		
		selectApi_baseWin.show();		
		var selectApi_baseGrid = selectApi_baseWin.down('cceafselectsysuser');
		selectApi_baseGrid.userId = this.userId;
		selectApi_baseGrid.name = this.name;
		selectApi_baseGrid.sex=this.sex;
		selectApi_baseGrid.certType=this.certType;
		selectApi_baseGrid.certCode=this.certCode;
		selectApi_baseGrid.userType=this.userType;
		selectApi_baseGrid.userGrade=this.userGrade;
		selectApi_baseGrid.houseRegion=this.houseRegion;
		selectApi_baseGrid.phone=this.phone;
		selectApi_baseGrid.address=this.address;
		selectApi_baseGrid.operatorNo=this.operatorNo;
		selectApi_baseGrid.operateTime=this.operateTime;
		selectApi_baseGrid.remark=this.remark;
		
		
		
    }
});